package com.education.student.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.education.model.MajorModel;
import com.education.model.Register;
import com.education.model.ResultDo;
import com.education.service.RegisterService;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * Created by Administrator on 2017/8/8.
 * 报名模块-
 */
@RestController
@RequestMapping("/api/student")
public class RegisterController {

    /**
     * 日志记录类
     */
    private static Logger logger = LogManager.getLogger(RegisterController.class);

    /**
     * 注入报名服务层接口
     */
    @Reference
    private RegisterService registerService;


    /**
     * 添加报名信息
     * @param register
     * @return
     * @throws Exception
     */
    @ApiOperation(notes = "/reg_information", httpMethod = "POST", value = "添加报名信息")
    @RequestMapping(value = "/reg_information",method = RequestMethod.POST)
    public ResultDo<Integer> addRegisterInformation(@RequestBody Register register)throws  Exception{
        /*System.out.println("进入后台");*/
        logger.info("这里是报名信息页面");
        //获取从前台传来的数据
       int rs= registerService.addRegisterInfomation(register);
       ResultDo<Integer> resultDo=new ResultDo<>();
       if(rs>0){
           resultDo.setResCode(0);
           resultDo.setResMsg("新增成功");
           resultDo.setResData(rs);
       }else{
           resultDo.setResCode(-1);
           resultDo.setResMsg("新增失败");
       }

        return resultDo;
    }

    /**
     * 2017/8/18 王娇
     * 查询所有专业
     * @return
     * @throws Exception
     */
    @ApiOperation(notes = "/getMajor", httpMethod = "GET", value = "查询专业")
    @RequestMapping(value="/getMajor",method = RequestMethod.GET)
    public ResultDo<Object> getMajor() throws Exception{
       List<MajorModel>list=registerService.getMajor();
        ResultDo<Object> resultDo=new ResultDo<>();
        resultDo.setResCode(0);
        resultDo.setResMsg("请求成功");
        resultDo.setResData(list);
        return resultDo;
    }

    /**
     * 2017/8/19 王娇
     * 生成入学测试题
     * 选择题
     * @return
     * @throws Exception
     */
    @ApiOperation(notes = "/enterTestSelect", httpMethod = "GET", value = "生成入学测试题")
    @RequestMapping(value="/enterTestSelect",method = RequestMethod.GET)
    public ResultDo<Object> enterTestSelect(Integer scoreType)throws Exception{
     Map<String,List> map= registerService.enterTestSelect(scoreType);
        ResultDo<Object> res=new ResultDo<Object>();
        res.setResCode(0);
        res.setResMsg("success");
        res.setResData(map);
        return res;
    }

    /**
     * 插入入学成绩
     * @param total
     * @param enterPhone
     * @return
     * @throws Exception
     */
    @ApiOperation(notes = "/addEnterScore", httpMethod = "GET", value = "插入入学成绩")
    @RequestMapping(value="/addEnterScore",method = RequestMethod.GET)
   public ResultDo<Integer> addEnterScore(Integer total,String enterPhone)throws Exception{
    int result=registerService.addEnterScore(total,enterPhone);
    ResultDo<Integer> resultDo=new ResultDo<>();
    if(result>0){
        resultDo.setResCode(0);
        resultDo.setResMsg("请求成功");
        resultDo.setResData(result);
    }
    return resultDo;
   }

    /**
     * 查询
     * @param searchMessage
     * @return
     * @throws Exception
     */
    @ApiOperation(notes = "/getRegisterStateByid", httpMethod = "GET", value = "模糊查询")
    @RequestMapping(value="/getRegisterStateByid",method = RequestMethod.GET)
   public ResultDo<Object> getRegister(String genre,String searchMessage)throws Exception{
    List<Register> list=registerService.getRegister(genre,searchMessage);
    ResultDo<Object> resultDo=new ResultDo<>();
    resultDo.setResCode(0);
    resultDo.setResMsg("请求成功");
    resultDo.setResData(list);
    return resultDo;
   }
}
